/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mobiwebinc.compconn.configuration;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author suraj
 */
public class MachineInfo {
private static String name = null;

    public static String getMachineName() {
        if (name == null) {
            if (System.getProperty("os.name").toLowerCase().contains("mac")) {
                byte[] cbuf = new byte[1000];
                try {
                    Process p = Runtime.getRuntime().exec("scutil --get ComputerName");
                    BufferedReader bf = new BufferedReader(new InputStreamReader(p.getInputStream()));
                    int length = p.getInputStream().read(cbuf);
                    name = new String(cbuf, 0, length, "UTF-8");
                } catch (IOException ex) {
                    Logger.getLogger(MachineInfo.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                try {
                    name = InetAddress.getLocalHost().getHostName();
                } catch (UnknownHostException ex) {
                    Logger.getLogger(MachineInfo.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

        }
        return name;
    }
}
